package com.m.springblog.service;

import com.m.springblog.mapper.UserInfoMapper;
import com.m.springblog.model.BlogInfo;
import com.m.springblog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogService blogService;
    public UserInfo queryById(Integer userId) {
        return userInfoMapper.querById(userId);
    }

    public UserInfo queryByName(String userName) {
        return userInfoMapper.queryByName(userName);
    }


    public UserInfo getAuthorInfo(Integer blogId) {
        BlogInfo blogInfo = blogService.getBlogDetail(blogId);
        if (blogInfo == null || blogInfo.getUserId() < 0) {return null;}
        return userInfoMapper.querById(blogInfo.getUserId());  
    }
}
